<?php
class isp_invoice_model extends MY_Model {
	var $model = 'isp_invoice';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT
					a.kode_kontrakaa,
					a.input_ppnjasdasdasd,
					d.kode_customer,
					d.nama,
					d.nama_perusahaan,
					d.alamat,
					d.kota,
					b.tgl_aktifasi,
					d.tgl_due,
					d.tgl_berakhir,
					a.periode_tagihan,
					c.jenis,
					c.bandwidth,
					a.abodemen,
					a.ppn,
					a.total,
					a.terbilang
					FROM
					ISP_CLIENT_INVOICE a
					LEFT JOIN ISP_CLIENT_KONTRAK b
					on a.KODE_KONTRAK = b.KODE_KONTRAK
					LEFT JOIN ISP_PRODUK c
					on b.kode_jenis = c.kode_produk
					LEFT JOIN ISP_CUSTOMER d
					on b.kode_customer = d.kode_customer		
					WHERE	(UPPER(d.kode_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(d.nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.kode_kontrak' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
				         
                   
				
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('isp_client_kontrak', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_client_kontrak', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_kode_inventori){
		$result = $this->db->get_where('isp_client_kontrak', array('kode_kontrak' => $as_kode_inventori));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_inventori)
	{
		$result = $this->db->get_where('isp_client_kontrak', array('kode_kontrak' => $as_kode_inventori));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			//if(	intval($this->get_data("SELECT COUNT(1) FROM isp_invoice WHERE kode_inventori = '".$arr_rule['kode_inventori']."'"))>0)
			//{
			//	return $this->error_delete.' [id: '.$arr_rule['kode_inventori']."]<br />";
			//}else{
				$this->db->delete('isp_client_kontrak', array('kode_kontrak' => $arr_rule['kode_kontrak']));
				return '';
			//}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>